package com.econ.powercloud.ems.controller;

import com.econ.powercloud.common.base.facade.pojo.MsgResult;
import com.econ.powercloud.common.base.facade.pojo.PageResult;
import com.econ.powercloud.ems.pojo.EmsClusterModelConfigVO;
import com.econ.powercloud.ems.pojo.requestVO.EmsClusterModelEdit;
import com.econ.powercloud.ems.pojo.requestVO.EmsClusterModelRequestVO;
import com.econ.powercloud.ems.service.biz.ClusterModelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author : zjf
 * @Description :
 * @Date : 2022/5/26 16:43
 * @Modified by : zjf
 */
@Api(tags = "电池簇模型")
@RestController
@RequestMapping(value = "/api/v2/cluster/model")
public class ClusterModelController extends ApiBaseController {

    @Autowired
    private ClusterModelService clusterModelService;

    @ApiOperation(value = "获取电池簇模型列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "modelName", value = "模块名称", dataType = "String",required = false),
            @ApiImplicitParam(paramType = "query", name = "pageNo", value = "页码", defaultValue = "1", dataType = "int"),
            @ApiImplicitParam(paramType = "query", name = "pageSize", value = "每页大小", defaultValue = "20", dataType = "int")
    })
    @GetMapping(value = "getClusterModelList")
    public MsgResult<PageResult<List<EmsClusterModelConfigVO>>> getCompanyInfo(@RequestParam(value = "modelName",required = false) String modelName,
                                                                               @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
                                                                               @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize){
        return successHandler(clusterModelService.selectByCondition(modelName, pageNo, pageSize));
    }

    @ApiOperation(value = "删除电池簇模型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "电池簇模型id", dataType = "int"),
    })
    @DeleteMapping(value = "deleteClusterModel")
    public MsgResult<String> deleteClusterModel(@RequestParam(value = "id") Integer id){
        clusterModelService.deleteById(id);
        return successHandler("删除电池簇模型成功！");
    }

    @ApiOperation(value = "新增电池簇模型")
    @PostMapping(value = "addClusterModel")
    public MsgResult<String> addClusterModel(@Validated @RequestBody EmsClusterModelRequestVO requestVO){
        return successHandler(clusterModelService.addClusterModel(requestVO));
    }

    @ApiOperation(value = "获取单个电池簇模型")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", value = "电池簇模型id", dataType = "int")
    })
    @GetMapping(value = "getClusterModelInfo")
    public MsgResult<EmsClusterModelConfigVO> getClusterModelInfo(@RequestParam(value = "id") Integer id){
        return successHandler(clusterModelService.selectByModelId(id));
    }

    @ApiOperation(value = "修改电池簇模型")
    @PutMapping(value = "updateClusterModel")
    public MsgResult<String> updateClusterModel(@Validated @RequestBody EmsClusterModelEdit emsClusterModelEdit){
        clusterModelService.updateClusterPackInfo(emsClusterModelEdit);
        return successHandler("修改电池簇模型成功！");
    }
}
